package com.myway.front.controller;

import com.alibaba.fastjson.JSON;
import com.myway.front.param.HotelParam;
import com.myway.front.pojo.TabHotel;
import com.myway.front.service.HotelService;
import com.myway.front.util.DataGridResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;


import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;


@Controller
@RequestMapping("/hotel")
public class HotelController {

    @Autowired
    private HotelService hotelService;

    /**
     * 热门目的地列表
     * @param param
     * @return
     */
    @RequestMapping("/hotelcharact.json")
    @ResponseBody
    public List<TabHotel>  selectHotelHomeCharact(HotelParam param){
        List<TabHotel> listCharact = hotelService.selectHotelHomeCharact(param);
        return listCharact;


    }

    /**
     * 主题酒店列表
     * @param param
     * @return
     */
    @RequestMapping("/hotelclassic.json")
    @ResponseBody
    public List<TabHotel> selectHotelHome(HotelParam param){
        List<TabHotel> listClassic = hotelService.selectHotelHomeClassic(param);
        return listClassic;
    }

    /**
     * hotelhome.jsp页面跳转的查询条件
     */

    @RequestMapping("/hotelcity.json")
    public String selectHotelCity(HotelParam param,Model model){
        model.addAttribute("city",param.getCity());
        return "hotel";
    }


    /**
     * 分页条件查询
     * @param param
     * @param page
     * @param rows
     * @return
     */
    @RequestMapping("/hotellist.json")
    @ResponseBody
    public DataGridResult selectHotel(HotelParam param,@RequestParam(defaultValue = "0",value = "page") Integer page,
                                      @RequestParam(defaultValue = "5",value = "rows") Integer rows){
        DataGridResult result = hotelService.selectHotelInf(param,page,rows);
        return  result;
    }

    @RequestMapping("/houseinf.json/{hotelId}")
    public String  selectHouseInf(@PathVariable(value = "hotelId") String hotelId,Model model){
       HashMap map = hotelService.selectHouseInf(hotelId);
       model.addAttribute("map",map);
       return "hotelDetail";
    }
    @RequestMapping("/validatelogin.json")
    public String  validateLogin(HttpServletRequest request){
         /*   TabUser user =request.getSession().getAttribute(""user);
            if( user!= null){
                return  "subOrder";
            }else{
                return  "login";
            }*/
        return "login";
    }

}
